package com.xique.park.controller.auto;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.xique.common.core.domain.R;
import com.xique.park.api.dto.ParkingOrderDTO;
import com.xique.park.service.biz.service.IParkingOrderBizService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xique.common.log.annotation.Log;
import com.xique.common.log.enums.BusinessType;
import com.xique.common.security.annotation.PreAuthorize;
import com.xique.park.bean.domain.ParkingOrderOn;
import com.xique.park.service.service.IParkingOrderOnService;
import com.xique.common.core.web.controller.BaseController;
import com.xique.common.core.web.domain.AjaxResult;
import com.xique.common.core.utils.poi.ExcelUtil;
import com.xique.common.core.web.page.TableDataInfo;

/**
 * 当前在场车辆的停车流水订单Controller
 *
 * @author xique
 * @date 2021-12-09
 */
@RestController
@RequestMapping("/parkingOrderOn")
public class ParkingOrderOnController extends BaseController
{
    @Autowired
    private IParkingOrderOnService parkingOrderOnService;

    @Autowired
    private IParkingOrderBizService parkingOrderBizService;

    /**
     * 查询当前在场车辆的停车流水订单列表
     */
    @PreAuthorize(hasPermi = "park:on:list")
    @GetMapping("/list")
    public TableDataInfo list(ParkingOrderOn parkingOrderOn)
    {
        startPage();
        List<ParkingOrderOn> list = parkingOrderOnService.selectParkingOrderOnList(parkingOrderOn);
        return getDataTable(list);
    }

    /**
     * 导出当前在场车辆的停车流水订单列表
     */
    @PreAuthorize(hasPermi = "park:on:export")
    @Log(title = "当前在场车辆的停车流水订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ParkingOrderOn parkingOrderOn) throws IOException
    {
        List<ParkingOrderOn> list = parkingOrderOnService.selectParkingOrderOnList(parkingOrderOn);
        ExcelUtil<ParkingOrderOn> util = new ExcelUtil<ParkingOrderOn>(ParkingOrderOn.class);
        util.exportExcel(response, list, "当前在场车辆的停车流水订单数据");
    }

    /**
     * 获取当前在场车辆的停车流水订单详细信息
     */
    @PreAuthorize(hasPermi = "park:on:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(parkingOrderOnService.selectParkingOrderOnById(id));
    }

    /**
     * 新增当前在场车辆的停车流水订单
     */
    @PreAuthorize(hasPermi = "park:on:add")
    @Log(title = "当前在场车辆的停车流水订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ParkingOrderOn parkingOrderOn)
    {
        return toAjax(parkingOrderOnService.insertParkingOrderOn(parkingOrderOn));
    }

    /**
     * 修改当前在场车辆的停车流水订单
     */
    @PreAuthorize(hasPermi = "park:on:edit")
    @Log(title = "当前在场车辆的停车流水订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ParkingOrderOn parkingOrderOn)
    {
        return toAjax(parkingOrderOnService.updateParkingOrderOn(parkingOrderOn));
    }

    /**
     * 删除当前在场车辆的停车流水订单
     */
    @PreAuthorize(hasPermi = "park:on:remove")
    @Log(title = "当前在场车辆的停车流水订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(parkingOrderOnService.deleteParkingOrderOnByIds(ids));
    }

    /**
     * 获取订单信息
     * @author shd
     * @date 2022/1/12 10:38
     * @param plate
     * @return com.xique.common.core.domain.R<com.xique.park.api.dto.ParkingOrderDTO>
     */
    @GetMapping("/getParkingOrder")
    public R<ParkingOrderDTO> getParkingOrder(String plate) {
        return parkingOrderBizService.getParkingOrder(plate);
    }
}
